﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ActiproSoftware.Windows.Controls.Ribbon.Controls;
using System.Windows.Controls.Primitives;

namespace AppDemo
{

    /// <summary>
    /// Interaction logic for RibbonWindow1.xaml.
    /// </summary>
    public partial class RibbonWindow1 : Window
    {

        public RibbonWindow1()
        {
            InitializeComponent();
            List<int> a = new List<int>();
            for (int i = 0; i < 2000; i++)
            {
                a.Add(i);
            }
            aaa.ItemsSource = a;
            aaa.PreviewMouseDown += new MouseButtonEventHandler(aaa_PreviewMouseDown);
           
            //aaa.AddHandler(ScrollBar.mo
            tip = new ToolTip();
            tip.HasDropShadow = false;
            tip.Placement = PlacementMode.Left;
            aaa.PreviewMouseUp += new MouseButtonEventHandler(aaa_PreviewMouseUp);
        }

        void aaa_PreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            tip.IsOpen = false;
            tip.PlacementTarget = null;
        }

        private ToolTip tip;

        void aaa_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            var element = e.OriginalSource as Microsoft.Windows.Themes.ScrollChrome;
            if (element == null) return;
            if (tip.PlacementTarget == null)
            {
                tip.PlacementTarget = element;
                tip.IsOpen = true;
               
            }
        }

        private void aaa_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            //12/400
            //23/76
            
            var item=aaa.ItemContainerGenerator.ContainerFromIndex(Convert.ToInt32(e.VerticalOffset)) as FrameworkElement;
            var count =Convert.ToInt32(aaa.ActualHeight / item.ActualHeight);
            //if (count > (aaa.Items.Count - e.VerticalOffset))
            //{
            //    count = Convert.ToInt32(aaa.Items.Count - e.VerticalOffset);
            //}
            aaaa.Text = (e.VerticalOffset + Math.Ceiling(e.VerticalOffset * (count - 2) / (aaa.Items.Count - count + 1))).ToString();
            tip.Content = aaaa.Text;
        }

    }
}
